
class ELMessage {
  msgBox = document.getElementById("msgBox");

  info(message) {
    if (this.flag){
      return;
    }
    this.addAnimatiton(message,"消息","info")
  }

  warning(message) {
    if (this.flag){
      return;
    }
    this.addAnimatiton(message,"警告","warning")
  }

  success(message) {
    if (this.flag){
      return;
    }
    this.addAnimatiton(message,"成功","success")
  }

  error(message) {
    if (this.flag){
      return;
    }
    this.addAnimatiton(message,"错误","error")
  }

  addAnimatiton(message,defaultMessage,messageClass) {
    this.flag = true;
    let msgContent = document.createElement('div');
    msgContent.className = `message-content message-content-${messageClass}`;
    msgContent.innerHTML = message || defaultMessage;
    this.msgBox.appendChild(msgContent)
    setTimeout(() => {
      msgContent.classList.add("show-message-content")
      setTimeout(() => {
        msgContent.classList.add("hide-message-content")
        setTimeout(() => {
          //动画结束,移除元素
          msgContent.remove();
          this.flag = false;
        }, 400)
      }, 1500);
    }, 100)
  }
}
export {
  ELMessage
}
